// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import {
    Alert,
    Swiper,
    SwiperItem,
    Marquee,
    MarqueeItem,
    PopupPicker,
    Cell,
    Group,
    Datetime,
    Toast,
    ConfirmPlugin,
    XTextarea,
    Selector,
    Checklist,
    ToastPlugin,
    LoadingPlugin,
    Swipeout,
    SwipeoutItem,
    SwipeoutButton,
    XHeader,
    Search,
    AlertPlugin
} from 'vux'
import getQuery from '@/utils/getQuery'
import noData from './commonComponents/noData'
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
import Uploader from 'vux-uploader'
import '@static/css/reset.css'
import '@static/css/formStyle.css'
import '@static/fontSize/iconfont.css'
import myMenu from '@/commonComponents/menu'
import $axiosAjax from './axios'
import Vuex from 'vuex'
import VueWechatTitle from 'vue-wechat-title'

import VueTouch from 'vue-touch'

Vue.use(VueTouch, { name: 'v-touch' })

Vue.use(VueWechatTitle)
Vue.use(noData)
Vue.component('myMenu', myMenu)
Vue.prototype.$axiosAjax = $axiosAjax
Vue.prototype.getQuery = getQuery

Vue.config.productionTip = false

let options = {
    history: true
}
Vue.use(preview, options)

Vue.use(ToastPlugin)
Vue.use(LoadingPlugin)
Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(Vuex)
Vue.component('alert', Alert)
Vue.component('Uploader', Uploader)
Vue.component('swiper', Swiper)
Vue.component('swiper-item', SwiperItem)
Vue.component('marquee', Marquee)
Vue.component('marquee-item', MarqueeItem)
Vue.component('popup-picker', PopupPicker)
Vue.component('cell', Cell)
Vue.component('group', Group)
Vue.component('datetime', Datetime)
Vue.component('toast', Toast)
Vue.component('x-textarea', XTextarea)
Vue.component('selector', Selector)
Vue.component('swipeout', Swipeout)
Vue.component('swipeout-item', SwipeoutItem)
Vue.component('swipeout-button', SwipeoutButton)
Vue.component('checklist', Checklist)
Vue.component('x-header', XHeader)
Vue.component('x-search', Search)

Vue.filter('toChinesNum', (num) => {
    let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
    let unit = ['', '十', '百', '千', '万']
    num = parseInt(num)
    let getWan = (tem) => {
        let strArr = tem.toString().split('').reverse()
        let newNum = ''
        for (let i = 0; i < strArr.length; i++) {
            newNum = (i == 0 && strArr[i] == 0 ? '' : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? '' : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum
        }
        return newNum
    }
    let overWan = Math.floor(num / 10000)
    let noWan = num % 10000
    if (noWan.toString().length < 4) {
        noWan = `0${noWan}`
    }
    return overWan ? `${getWan(overWan)}万${getWan(noWan)}` : getWan(num)
})

Vue.filter('unescape', function (html) {
    return html
        .replace(html ? /&(?!#?\w+;)/g : /&/g, '&amp;')
        .replace(/&lt;/g, '<')
        .replace(/&gt;/g, '>')
        .replace(/&quot;/g, '"')
        .replace(/%23/g, '#')
})

Vue.filter('myTrim', (value) => {
    let str = value || ''
    return str.replace(/(^\s*)|(\s*$)/g, '')
})
/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    components: {
        App
    },
    template: '<App/>'
})
